package com.ymttest.database.sqlwapper.CSIM;

import java.math.BigDecimal;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ymatou.iapi.csim.parameter.PagingResult;
import com.ymt.core.tool.Logger;
import com.ymt.database.SqlManager;
import com.ymttest.database.model.YmtFundDimension;
import com.ymttest.database.model.ymt_cssession;
import com.ymttest.utils.EnvSetup;

/************************************************************************************
 * @File name : ymt_cssessionWapper.java
 * @Author : 吴文
 * @Date : 2016年11月24日
 * @Copyright : 洋码头
 *csim
 ************************************************************************************/
public class ymt_cssessionWapper {
	SqlManager manage;

	
	public ymt_cssessionWapper() {
		manage = new SqlManager("ymtcsim" + EnvSetup.getEnv());
		 
	}
	public ymt_cssession selectByPrimaryKey(String id) throws InterruptedException {
		ymt_cssession model=new  ymt_cssession();
		List<ymt_cssession> list = manage.getSelectResults("com.ymttest.database.mapping.ymt_cssessionMapper.selectByPrimaryKey",id);
		if(list.size()>0)
			 model=list.get(0);
		return model;
	}
	
	public  ymt_cssession selectBy(Map<String,Object> map) throws InterruptedException {
		ymt_cssession model=new  ymt_cssession();
		List<ymt_cssession> list = manage.getSelectResults("com.ymttest.database.mapping.ymt_cssessionMapper.selectBy",map);
		if(list.size()>0)
			 model=list.get(0);
		manage.commit();
		return model;
	}
	
	public  List<ymt_cssession> selectAllBy(Map<String,Object> map) throws InterruptedException {
		List<ymt_cssession> list = manage.getSelectResults("com.ymttest.database.mapping.ymt_cssessionMapper.selectBy",map);
		manage.commit();
		return list;
	}
	
	public int selectBy_Count(Map<String,Object> map)
	{
		List<Map> resultMap = manage.getSelectResults("com.ymttest.database.mapping.ymt_cssessionMapper.selectBy_Count",map);
		
		int result=Integer.parseInt(resultMap.get(0).get("count").toString());
		manage.commit();
		return result;
	}
	
	
	public int updateByPrimaryKey(ymt_cssession ymt_cssession)
	{
	   int count= manage.update("com.ymttest.database.mapping.ymt_cssessionMapper.updateByPrimaryKey",ymt_cssession);	
	   manage.commit();
	   return count;
	}
	
	public int deleteByUserId(Map<String,Object> map)
	{
	   int count= manage.update("com.ymttest.database.mapping.ymt_cssessionMapper.deleteByUserId",map);	
	   manage.commit();
	   return count;
	}
	
	
	public PagingResult<ymt_cssession> getSessionListByPaging(String sqlWhere ,int offset, int pageSize)
    {
    	HashMap<String,Object> map=new HashMap();
    	map.put("sqlWhere", sqlWhere);
    	map.put("offset", offset);
    	map.put("pageSize", pageSize);
	    List<Map> resultMap = manage.getSelectResults("com.ymttest.database.mapping.ymt_cssessionMapper.getSessionListByPaging",map);
		int count=Integer.parseInt(resultMap.get(0).get("count").toString());
		List<ymt_cssession> sessionPos = (List<ymt_cssession>) resultMap.get(1);
		manage.commit();
		return of(count,sessionPos);
    }
    
	
	
	public int getSessionListCount(String sqlWhere)
    {
    	HashMap<String,Object> map=new HashMap();
    	map.put("sqlWhere", sqlWhere);
	    List<Map> resultMap = manage.getSelectResults("com.ymttest.database.mapping.ymt_cssessionMapper.getSessionListCount",map);
		int count=Integer.parseInt(resultMap.get(0).get("count").toString());
		return count;
    }
	
	public List<ymt_cssession> getSessionListByPage(String sqlWhere ,int offset, int pageSize)
    {
    	HashMap<String,Object> map=new HashMap();
    	map.put("sqlWhere", sqlWhere);
    	map.put("offset", offset);
    	map.put("pageSize", pageSize);
	    List<ymt_cssession> resultMap = manage.getSelectResults("com.ymttest.database.mapping.ymt_cssessionMapper.getSessionListByPage",map);
		manage.commit();
		return resultMap;
    }
	
	public List<ymt_cssession> getNavigateSession(String sqlWhere ,String subsqlwhere)
    {
    	HashMap<String,Object> map=new HashMap();
    	map.put("sqlwhere", sqlWhere);
    	map.put("subsqlwhere", subsqlwhere);
	    List<ymt_cssession> resultMap = manage.getSelectResults("com.ymttest.database.mapping.ymt_cssessionMapper.getNavigateSession",map);
		manage.commit();
		return resultMap;
    }
	public List<ymt_cssession> selectBysessionNumber(List<String> sessionNumberStr)
	{
	    List<ymt_cssession> resultMap = manage.getSelectResults("com.ymttest.database.mapping.ymt_cssessionMapper.selectBysessionNumber",sessionNumberStr);
		manage.commit();
		return resultMap;
	}
	
    public static <T> PagingResult<T> of(int recordCount, List<T> records){
        PagingResult<T> result = new PagingResult<T>();
        result.setRecordCount(recordCount);
        result.setRecords(records);
        return result;
    }
	public static void main(String args[]) {
	  
	}
	
	
}
